﻿Chenxin.UI.CommissionManage=Chenxin.extend(Chenxin.UI.PageCommon,{
	autoInitForm:false,
	actionUrl:'service/trusthandler.ashx',
	createGrid:function(){
		return new Chenxin.UI.Pagination({
			actionUrl:this.actionUrl+'?op=getlist',
			domId:'page',
			renderTo: 'commission_table',
			render:function(data){
				document.getElementById('commission_table').innerHTML=data;
			}
		});
    },
	//作废
	invalid:function(){
		if(!confirm('确定作废这条委托记录？')){
			return;
		}
		var _this=this;
		Chenxin.ajax({
			url:this.actionUrl,
			type:'get',
			data:{op:'cancel',entrustid:this.currentId},
			onSuccess:function(data,msg){
				alert(msg);
				_this.grid.reload();
			}
		});
	},
	//恢复
	resume:function(){
		if(!confirm('确定作废这条委托记录？')){
			return;
		}
		var _this=this;
		Chenxin.ajax({
			url:this.actionUrl,
			type:'get',
			data:{op:'uncancel',entrustid:this.currentId},
			onSuccess:function(data,msg){
				alert(msg);
				_this.grid.reload();
			}
		});	
	},
	initEvent:function(){
		var _this=this;
		
		//查询菜单点击展开事件
		$(".arrow").click(function(){
			$("#panel").slideToggle("slow");
			$(this).toggleClass("up"); return false;
		});
		
		//查看
		$('.a_commission_view').live('click',function(){
		    _this.currentId = this.name;
		    _this.form.permitParam = { currentId: _this.currentId };
			_this.view();
			_this.form.setTitle('查看委托');
		});
		//编辑
		$('.a_commission_edit').live('click',function(){
		    _this.currentId = this.name;
		    _this.form.permitParam = { currentId: _this.currentId };
			_this.edit();
			_this.form.setTitle('编辑委托');
		});
		
		//删除
		$('.a_commission_del').live('click',function(){
		    _this.currentId = this.name;
			_this.del();
		});
		
		//作废
		$('.a_commission_invalid').live('click',function(){
		    _this.currentId = this.name;
		    _this.form.permitParam = { currentId: _this.currentId };
			_this.invalid();
		});
		
		//恢复
		$('.a_commission_resume').live('click', function() {
		    _this.form.permitParam = { currentId: _this.currentId };
			_this.currentId=this.name;
			_this.resume();
		});
		
		
	},
	createForm:function(){
		return new Chenxin.UI.CommissionForm({
		        scope: this,
		        alwaysCheckPermit: true,
				beforeFitData:function(model){
					//this.form.employeeId.initValue=model.EmployeeId;
					// this.form.employeeId.param.fatherid=model.EmpDepartId;
					// this.form.employeeId.reload(model.EmployeeId);	
					
					model.EntrustCode=model.EntrustCode.replace('wt','');
					model.StartTime = model.StartTime.split(" ")[0];
					model.EndTime = model.EndTime.split(" ")[0];
					if (this.form.op == "edit") {

					    $("#wtbh").attr('disabled', 'disabled');
                        var strType = model.EntrustType;
                        switch(strType){
                            case "10":
                                //_this.findByName("TotalPrice").unFormValidator(true);
                                // _this.findByName("RentPrice").unFormValidator(false);
                                // 租赁价格
                                $("#wtzljg").unFormValidator(true);
                                //建筑面积
                                $("#wtjzmj").unFormValidator(false);
                                //房屋总价
                                $("#wtfwzj").unFormValidator(false);
                                break;
                            case "20":
                                //_this.findByName("TotalPrice").unFormValidator(false);
                                //_this.findByName("RentPrice").unFormValidator(true);
                                // 租赁价格
                                $("#wtzljg").unFormValidator(false);
                                //建筑面积
                                $("#wtjzmj").unFormValidator(true);
                                //房屋总价
                                $("#wtfwzj").unFormValidator(true);
                                break;
                            case "30":
                                // _this.findByName("TotalPrice").unFormValidator(false);
                                // _this.findByName("RentPrice").unFormValidator(false);
                                // 租赁价格
                                $("#wtzljg").unFormValidator(false);
                                //建筑面积
                                $("#wtjzmj").unFormValidator(false);
                                //房屋总价
                                $("#wtfwzj").unFormValidator(false);
                                break;
                        }
				    }
				},
				afterGetFormJson:function(json){
					if(this.form.op=='edit'){
					    json.EntrustCode = "wt" + json.EntrustCode;
						Chenxin.applyIf(json,this.currentModel);
					}
				}
			});
	},
	createSearch:function(){
		return new Chenxin.UI.CommissionMgrSearch({
			scope:this
		});
	},
	initComponent:function(){
		Chenxin.UI.CommissionManage.superclass.initComponent.call(this);
	}
});


/**
*查询面板
*/
Chenxin.UI.CommissionMgrSearch=Chenxin.extend(Chenxin.UI.SearchCommon,{
	id:'commission_search',
	initEvent:function(){
		var _this=this;
		$('#btn_search').click(function(){
			_this.scope.reloadGrid();
		});
	},
	createComboList:function(){		
            var region=new Chenxin.UI.ParameterCombo({
				name:'region',
				containerId:'#region',
				key:'System.Region',
				tbxWidth:45,
				inModelType:'txt'
			});
            var business = new Chenxin.UI.Combo({
                containerId: '#business',
                tbxWidth: 45,
                items: comboCommon.trustBusinessType
            });
            var status = new Chenxin.UI.Combo({
                containerId: '#status',
                tbxWidth: 45,
                items: comboCommon.trustStatus
            });
            var combl = new Chenxin.UI.StructComboList({
				cityAfterSelected:function(val){
					if(val==combl.city.defVal){
						region.clearItems();
					}else{
						region.param.cityid=val;
						region.param.filter='bycity';
						region.reload();
					}
				}
			});
            var structs = combl.comboList;
            structs.push(status);
			structs.push(region);
			structs.push(business);
            return structs;
	},
	initComponent:function(){
		Chenxin.UI.CommissionMgrSearch.superclass.initComponent.call(this);
	}
});

function setunitprice() {
    if ($("#wtjzmj").val() != "" && $("#wtfwzj").val() != "") {
            var value1 = parseFloat(parseFloat($("#wtfwzj").val() / $("#wtjzmj").val()));
            $("#wtfwdj").val(Math.round(value1 * 100) / 100.00);
    }
}

$(document).ready(function(){
	var commissionMgr=new Chenxin.UI.CommissionManage();	
});





